package day230512;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/5/13 17:05
 * Emacs 计算器
 */
public class Main02 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            int n = scan.nextInt(); // 获取输入的个数
            Deque<Integer> stack = new ArrayDeque<>();
            while (n-- != 0) {
                String input = scan.next();
                if (isNumber(input.charAt(0))) {
                    // 如果是数字
                    stack.push(Integer.valueOf(input));
                } else {
                    // 如果不是数字, 说明是操作符号
                    // 一次弹栈两个操作数, 计算后压栈
                    int right = stack.pop();
                    int left = stack.pop();
                    int result = calculate(left, right, input);
                    stack.push(result);
                }
            }
            System.out.println(stack.pop());
        }
        scan.close();
    }

    // 判断是否为数字
    private static boolean isNumber(char c) {
        return c >= '0' && c <= '9';
    }

    // 四则运算
    private static int calculate(int num1, int num2, String operation) {
        switch (operation) {
            case "+":
                return num1 + num2;
            case "-":
                return num1 - num2;
            case "*":
                return num1 * num2;
            case "/":
                return num1 / num2;
            default:
                return -1;
        }
    }
}
